//
//  EVETrackerAppDelegate.m
//  EVETracker
//
//  Created by Scott Guyer on 7/16/08.
//  Copyright __MyCompanyName__ 2008. All rights reserved.
//


#import "RootPilotViewController.h"
#import "SkillTabVC.h"
#import "EVETrackerAppDelegate.h"
#import "Character.h"
#import "defs.h"


@implementation EVETrackerAppDelegate

@synthesize window;
@synthesize tabBarController;


- (void)applicationDidFinishLaunching:(UIApplication *)application 
{
	
	rootPilotVC = [[RootPilotViewController alloc] init];
	rootSkillsVC = [[SkillTabVC alloc] initWithNibName:@"SkillTabView" bundle:nil];
	
	NSArray* vcs = [NSArray arrayWithObjects:rootPilotVC,rootSkillsVC,nil];
	[tabBarController setViewControllers:vcs];
		
	// Add the tab bar controller's current view as a subview of the window
	[window addSubview:tabBarController.view];
	[tabBarController.view setAutoresizesSubviews:YES];
}

- (void)applicationWillResignActive:(UIApplication *)application
{
	[Character savePilots:rootPilotVC.pilots];
}

- (void)applicationDidBecomeActive:(UIApplication *)application
{
	int expired = [rootPilotVC updateCompletedPilotsCount];
	[application setApplicationIconBadgeNumber:expired];
}

- (void)applicationWillTerminate:(UIApplication *)application
{
	[Character savePilots:rootPilotVC.pilots];		
	int expired = [rootPilotVC updateCompletedPilotsCount];
	[application setApplicationIconBadgeNumber:expired];

}

- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application
{
	NSLog(@"%s", __FUNCTION__);
	
	// Just in case, because we may get nuked by the OS here soon
	[Character savePilots:rootPilotVC.pilots];
	
	// Do something like purging the skills browser in the pilot view if it is not being shown
	[rootPilotVC jenny];
	
	if ( [tabBarController selectedIndex] == 0 )
	{
		// Pilot pager is selected, go ahead and cleanup the skills view
		[rootSkillsVC jenny];
	}
	
}


- (void)dealloc 
{
	NSLog(@"%s 0x%x", __FUNCTION__, self);
	
	WIPE( tabBarController)
	WIPE( rootPilotVC)
	WIPE( window)
	
	[super dealloc];
}

@end

